﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CF_DAL_WS.Models;

namespace CF_DAL_WS.DTO
{
    public class CartDTO
    {
        public int RecordId { get; set; }
        public string CartId { get; set; }
        public int FoodID { get; set; }
        public int Count { get; set; }
        public int RestaurantID { get; set; }
        public DateTime DateCreated { get; set; }

        public static CartDTO Translate(Cart Entity)
        {
            if (Entity != null)
            {
                var dto = new CartDTO
                {
                    RecordId = Entity.RecordId,
                    CartId = Entity.CartId,
                    FoodID = Entity.FoodID.Value,
                    Count = Entity.Count.Value,
                    RestaurantID = Entity.RestaurantID.Value,
                    DateCreated = Entity.DateCreated.Value
                };
                return dto;
            }
            return null;
        }

        public static Cart Reverse(CartDTO obj)
        {
            var entity = new Cart
            {
                RecordId = obj.RecordId,
                CartId = obj.CartId,
                FoodID = obj.FoodID,
                Count = obj.Count,
                RestaurantID = obj.RestaurantID,
                DateCreated = obj.DateCreated
            };
            return entity;
        }

        public void UpdateEntity(ref Cart entity)
        {
            entity.Count = Count;
        }
    }
}